﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DLULearningNetworkModel
{
    public partial class SecurityQuestions
    {
        public static List<SecurityQuestion> All()
        {
            DLULNEntities entities = new DLULNEntities();
            return entities.SecurityQuestions.ToList();
        }

        public static int Add(SecurityQuestion _SecurityQuestion)
        {
            try
            {
                using (DLULNEntities db = new DLULNEntities())
                {
                    db.SecurityQuestions.AddObject(_SecurityQuestion);
                    if (db.SaveChanges() > 0)
                    {
                        return 1;
                    }
                    return 0;

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int Update(SecurityQuestion _SecurityQuestion)
        {
            try
            {
                using (DLULNEntities db = new DLULNEntities())
                {
                    SecurityQuestion entity = db.SecurityQuestions.SingleOrDefault(en => en.SecurityQuestionID_u == _SecurityQuestion.SecurityQuestionID_u);
                    if (entity == null)
                    {
                        return 0;
                    }
                    entity.Content_s = _SecurityQuestion.Content_s;
                    if (db.SaveChanges() > 0)
                    {
                        return 1;
                    }
                    return 0;

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int Delete(SecurityQuestion _SecurityQuestion)
        {
            try
            {
                using (DLULNEntities db = new DLULNEntities())
                {
                    SecurityQuestion entity = db.SecurityQuestions.SingleOrDefault(en => en.SecurityQuestionID_u == _SecurityQuestion.SecurityQuestionID_u);
                    if (entity == null)
                    {
                        return 0;
                    }
                    db.SecurityQuestions.DeleteObject(entity);
                    if (db.SaveChanges() > 0)
                    {
                        return 1;
                    }
                    return 0;

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
